package com.demo.work.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author 19042980
 */
public class ExcelUtil {

    static Pattern pattern = Pattern.compile("[A-Z]+");

    public static int getIndex(String column) {
        if (column == null || column.isEmpty()){
            throw new RuntimeException("column can not be null");
        }
        column = column.toUpperCase();
        Matcher matcher = pattern.matcher(column);
        if (!matcher.matches()){
            throw new RuntimeException("column illegal");
        }
        char[] chars = column.toCharArray();
        int result = 0;
        for (int i = 0; i < chars.length; i++) {
            result += (chars[i] - 64) * Math.pow(26, chars.length - i - 1);
        }

        return result - 1;
    }
}
